package leedcode;

/**
 * @description:
 * @author: zk
 * @date: 2023-02-08 20:26
 */
public class Question_191 {
    private static final char ONE = '1';

    // you need to treat n as an unsigned value
    public static int hammingWeight(int n) {
        String binaryString = Integer.toBinaryString(n);
        char[] chars = binaryString.toCharArray();

        int count = 0;
        for (char c : chars) {
            if (ONE == c) {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(hammingWeight(3));
    }

}
